package net.rock;

import net.rock.config.BookConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;

import javax.annotation.PostConstruct;
import java.io.File;

@SpringBootApplication
@EnableEurekaClient
public class BookApplication {
    @Autowired
    private BookConfig bookConfig;

    @PostConstruct
    public void checkUploadPath() {
        File uploadPath = new File(String.format("%s%s", BookConfig.workDir, bookConfig.getUploadPath()));
        if (!uploadPath.exists()) {
            boolean res = uploadPath.mkdirs();
            if (!res) {  // failed to create dirs
                throw new RuntimeException("Failed to make directory: " + bookConfig.getUploadPath());
            }
        }
    }

    public static void main(String[] args) {
        SpringApplication.run(BookApplication.class, args);
    }
}
